//
//  JYJColumnListTableViewCell.m
//  HappyListen
//
//  Created by 冀永金 on 16/9/3.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJColumnListTableViewCell.h"
#import "BaseLabel.h"
#import "JYJTAMacro.h"
#import "Masonry.h"
#import "JYJColumnListModel.h"
#import "UIImageView+WebCache.h"

@interface JYJColumnListTableViewCell ()
@property (nonatomic, strong) UIImageView *backImage;
@property (nonatomic, strong) UIImageView *musixImage;
@property (nonatomic, strong) BaseLabel *nameLabel;
@property (nonatomic, strong) BaseLabel *label;
@property (nonatomic, strong) BaseLabel *lastMusicLabel;
@property (nonatomic, strong) UIImageView *playImage;
@property (nonatomic, strong) BaseLabel *playCountLabel;
@property (nonatomic, strong) BaseLabel *managerLabel;
@end
@implementation JYJColumnListTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return  self;
}
- (void)createSubViews {
    self.musixImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.musixImage];
    _musixImage.backgroundColor = [UIColor yellowColor];
    self.backImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"login_channel_item"]];
    [self.contentView addSubview:_backImage];
    self.nameLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_nameLabel];
    _nameLabel.textColor = [UIColor whiteColor];
    _nameLabel.text = @"愚者无敌";
    _nameLabel.textAlignment = 0;
    self.label = [[BaseLabel alloc]init];
    [self.contentView addSubview:self.label];
    self.label.textAlignment = 0;
    self.label.text = @"最新节目:";
    self.label.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    self.label.font = [UIFont systemFontOfSize:13];
    self.lastMusicLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_lastMusicLabel];
    _lastMusicLabel.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    _lastMusicLabel.textAlignment = 0;
    _lastMusicLabel.font = [UIFont systemFontOfSize:13];
    self.playImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"catinfo_play_cnt"]];
    [self.contentView addSubview:_playImage];
    self.playCountLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_playCountLabel];
    self.playCountLabel.font = [UIFont systemFontOfSize:14];
    self.playCountLabel.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    self.managerLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_managerLabel];
    self.managerLabel.font = [UIFont systemFontOfSize:14];
    self.managerLabel.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.height.mas_equalTo(80);
    }];
    [self.musixImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-2);
        make.left.equalTo(self.contentView.mas_left).with.offset(2);
        make.height.mas_equalTo(76);
        make.width.mas_equalTo(82);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(22);
        make.left.equalTo(self.musixImage.mas_right).with.offset(35);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(30);
    }];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(57);
        make.left.equalTo(self.musixImage.mas_right).with.offset(35);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(20);

    }];
    [self.lastMusicLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(57);
        make.left.equalTo(self.label.mas_right).with.offset(-50);
        make.width.mas_equalTo(220);
        make.height.mas_equalTo(20);
    }];
    [self.playImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(82);
        make.left.equalTo(self.musixImage.mas_right).with.offset(30);
        make.width.mas_equalTo(10);
        make.height.mas_equalTo(10);
    }];
    [self.playCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(78);
        make.left.equalTo(self.playImage.mas_right).with.offset(5);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
    }];
    [self.managerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(78);
        make.left.equalTo(self.playCountLabel.mas_right).with.offset(10);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(20);
    }];
}
- (void)setListModel:(JYJColumnListModel *)listModel {
    _listModel = listModel;
    [self.musixImage sd_setImageWithURL:[NSURL URLWithString:listModel.item_thumbimg] placeholderImage:PLACEHOLDERIMAGE];
    self.nameLabel.text = listModel.item_name;
    self.lastMusicLabel.text = listModel.item_lastmusic;
    NSMutableArray *playString = [NSMutableString stringWithFormat:@"%ld",listModel.item_views].mutableCopy;
    if (listModel.item_views >= 10000) {
        NSString *playString = [NSString stringWithFormat:@"%ld",listModel.item_views / 10000];
        self.playCountLabel.text =  [NSString stringWithFormat:@"%@万",playString];
        
    }else {
        self.playCountLabel.text =  [NSString stringWithFormat:@"%@",playString];
    }

    self.managerLabel.text = [NSString stringWithFormat:@"by %@",listModel.item_manager];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
